﻿class ViewerDelegate {
    private var viewName:String;

    public function setName(aviewName:String):void {
        viewName = aviewName
    }

    private function getName():String {
        return viewName;
    }

    private var controller:Controller;

    public function setController(c:Controller):void {
        controller = c;
        controller.addViewer(this);
    }

    private function getController():Controller {
        return controller;
    }

    public notifyServerDoSth(sth) {
        controller.notifyServerDoSth(sth);
    }
}

class Viewer {
    private var delegate:ViewerDelegate;
    public setDelegate(adelegate:ViewerDelegate):void {
        delegate = adelegate;
    }

    public Viewer() {
    }

    private notifyServerDoSth(sth) {
        delegate.notifyServerDoSth(sth);
    }

    public doSth(sth) {
        // viewer execute sth
    }
}

class Controller {
    private viewer;
    private so

    addViewer(v) {
        viewer = v;
    }

    setName() {
        so = new SO(v.getName());
    }

    public notifyServerDoSth(sth) {
        // sync, server do sth
        so.setP(key, sth);
    }

    private doSth() {
        sth = so.getSth();
        v.doSth(sth)
    }
}

var delegate:ViewerDelegate = new ViewerDelegate();
delegate.setName(vname);
var c:Controller = new Controller();
delegate.setController(c);
c.addViewer(v);








